#include<string>
#include<vector>
#include<array>
#include<unordered_map>
#include<algorithm>
#include<limits>
class Solution {
public:
    int minEatingSpeed(std::vector<int>& piles, int h) {
        int  l = 1;
        int  r = 0;
        for (const int a:piles)
        {
            r = std::max(r,a);
        }
        while (l<=r)
        {
            int mid = l + (r-l)/2;
            if (f(piles,h,mid))
            {
                r=mid-1;
            }
            else
            {
                l=mid+1;
            }
        }
        return l;
    }
    bool f(std::vector<int>& piles, int h,int speed)
    {
        int rh = 0;
        int p = 0;
        int n = piles.size();
        while (rh<=h&&p<n)
        {
            rh+=(piles[p++]+speed-1)/speed;
        }
        return rh<=h;
    }
};
